//https://leetcode.cn/problems/kth-missing-positive-number/
#include<iostream>
#include<vector>
using namespace std;
int findKthPositive(vector<int>& arr, int k) {
    int count = arr[0] - 1;
    if (k <= count)
        return k;
    int perv = 0, cur = 1;
    while (1)
    {
        int tmp = 0;
        tmp = arr[cur] - 1 - arr[perv];
        if (count + tmp < k)
        {
            count += tmp;
            cur++;
            perv++;
        }
        else
            return arr[perv] + k - count;
    }
}
int main()
{
    vector<int> arr(5);
    arr[0] = 2;
    arr[1] = 3;
    arr[2] = 4;
    arr[3] = 7;
    arr[4] = 11;
    cout<<findKthPositive(arr, 5);
    return 0;
}